//
//  ViewController.m
//  5-24
//
//  Created by mac on 16-5-24.
//  Copyright (c) 2016年 ztt. All rights reserved.
//

#import "ViewController.h"
#import "TwoViewController.h"
#import "ThreeViewController.h"

@interface ViewController ()
{
    NSArray *data;
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.

    self.navigationItem.title = @"果味小茶";
    self.view.backgroundColor = [UIColor redColor];
    self.refreshControl = [UIRefreshControl new];
    
    //self.refreshControl.tintColor = [UIColor greenColor];//改刷新颜色。
//  self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"刷新中..." attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    //self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"停止" style:UIBarButtonItemStylePlain target:self action:@selector(onClick:)];//把右上角的按钮设为停止，点击会停止刷新。
    
    //self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(onClick:)];//图标变为照相机。
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"5"] style:UIBarButtonItemStylePlain target:self action:@selector(onClick:)];//把右上角的按钮变成第五张图片。
    
    //UIImageView *iv = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"4"]];
    //self.navigationItem.titleView = iv;//上下两段是把标题改成图片。
    data = @[
             @"抹茶奶茶",
             @"椰香奶茶",
             ];
    
}

- (void)onClick:(id)sender
{
    [self.refreshControl endRefreshing];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
    *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    NSString *imgName = [NSString  stringWithFormat:@"%d",indexPath.row +1];
    cell.imageView.image = [UIImage imageNamed:imgName];
    
    cell.imageView.layer.cornerRadius = 18;
    cell.imageView.clipsToBounds = YES;
    
    cell.textLabel.text = data[indexPath.row];
    //cell.backgroundColor = [UIColor colorWithRed:5*indexPath.row/522.0 green:12*indexPath.row/900.0 blue:19*indexPath.row/255.0 alpha:1];
    cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        TwoViewController *cn = [TwoViewController new];
        [self.navigationController pushViewController:cn animated:YES];
    }
    if (indexPath.row == 1)
    {
        ThreeViewController *tn = [ThreeViewController new];
        [self.navigationController pushViewController:tn animated:YES];
    }
    
    //self.hidesBottomBarWhenPushed = YES;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
